var queryParam = null;
$(function(){
    var id = $("#exampleId").val();
    queryParam = {"example_id" : id};
    getListPage();
});

function getListPage(param){
    param = $.extend(queryParam,param);
    $.ajax({
        type : "post",
        url : "htmlWeb/getExampleDiscussListByPage",
        data: param,
        async: false,
        success : function(data){
            $("#caseDiscussPageHead ~ tr").remove();
            var str = "";
            $.each(data.rows,function(i,obj){
                obj = trimEmpty(obj);
                var createTime = formatDate(obj.createTime,"yyyy-MM-dd");
                var content = subStr(obj.content);
                str += '<tr><td><p>' + obj.id + '</p></td>' +
                    '<td><span>' + obj.name + '</span></td>' +
                    '<td><p><img src="http://img.boyitongcheng.com/' + obj.imgUrl + '" width="80px" height="60px"></p></td>' +
                    '<td><span>' + obj.score + '</span></td>' +
                    '<td><span>' + content + '</span></td>' +
                    '<td><span>' + createTime + '</span></td>' +
                    '<td><span class="userSpan"><a class="cur" href="javascript:void(0);" onclick="editDiscuss('+ obj.id + ')">编辑</a>' +
                    '<a class="cur" href="javascript:void(0);" onclick="deleteDiscuss('+ obj.id + ')">删除</a></span></td></tr>';
            });
            $("#caseDiscussPageHead").after(str);
            createPage(data);

        },
        error : function(data){
            console.log(data);
        }
    });
}
function editDiscuss(id) {
    var jsPath = "../../by-webhtml/assets/js/system/system_discussAdd.js";
    $(".mainDiv").load("/htmlWeb/systemDiscussAddHtml", '', function () {
        $("#exampleId_update").val(queryParam.example_id);
        $("#exampleDiscussId_update").val(id);
        $.getScript(jsPath);
    });
}

function deleteDiscuss(id) {
    $.post("htmlWeb/deleteExampleDiscuss",{"id" : id},function(data){
        tip("删除评论成功");
        goPage(1);
    });
}